package com.example.demo.service;

import com.example.demo.mapper.FavoriteMapper;
import com.example.demo.model.Favorite;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FavoriteService {
    @Autowired
    private FavoriteMapper favoriteMapper;

    public boolean addFavorite(Integer userId, Integer productId) {
        if (favoriteMapper.getByUserAndProduct(userId, productId) != null) {
            return false;
        }
        return favoriteMapper.add(userId, productId) > 0;
    }

    public boolean removeFavorite(Integer userId, Integer productId) {
        return favoriteMapper.remove(userId, productId) > 0;
    }

    public List<Favorite> getUserFavorites(Integer userId) {
        return favoriteMapper.getByUserId(userId);
    }

    public boolean isFavorite(Integer userId, Integer productId) {
        return favoriteMapper.getByUserAndProduct(userId, productId) != null;
    }
} 